package com.hxx.day2;

import org.junit.Test;

/**
 * static关键字
 */
public class TestDemo5 {

    @Test
    public void test1(){
        Student s1 = new Student();
        System.out.println(s1.getCount());
        Student s2 = new Student();
        System.out.println(s2.getCount());

    }

    /**
     * 通过类直接调用static修饰的变量
     */
    @Test
    public void test2(){
        Student s1 = new Student();
        System.out.println(Student.count);

        Student s2 = new Student();
        System.out.println(Student.count);

    }

}

class Student{
    /*
      静态变量在类加载的时候初始化
      并且静态变量只初始化一次
    */
    public static int count;

    public Student(){
        count++;
    }

    public int getCount(){
        return count;
    }
}


















